$(function(){
    Ext.onReady(function() {
        var obj = {
            formPanel: null,
            init: function () {
                var that = this;

                    that.formPanel = Ext.create('Ext.form.Panel', {
                        renderTo: document.body,
                        xtype: 'form',
                        title: '登录',
                        height: 200,
                        width: 300,
                        right: '50%',
                        style:{
                            'position': 'absolute',
                            'left': '75%',
                            'top': '40%',
                            'transform': 'translate(-150px,-100px);'
                        },
                        bodyPadding: 10,
                        defaultType: 'textfield',
                        items: [{
                            fieldLabel: '账号',
                            name: 'account',
                            id: 'account',
                            allowBlank: false,
                            tooltip: '请输入您的账号',
                            blankText: '请输入您的账号'
                        }, {
                            inputType:'password',
                            fieldLabel: '密码',
                            name: 'password',
                            tooltip: '请输入密码',
                            allowBlank: false,
                            blankText: '请输入密码',
                            regex: /^[\s\S]{0,32}$/,
                            regexText: '密码长度不能超过32个字符'
                        }, {
                            xtype: 'button',
                            text: '账号注册',
                            style: {
                                'margin': '15px 0 0 0',
                                'padding': '3px 10px',
                                'border-color': '#FF9800',
                                'background-image': '-webkit-linear-gradient(top, #f7ac3f, #efac4a 50%, #f79f1f 51%, #f9be67);'
                            },
                            handler: function() {
                                window.location.href = './register.html';

                            }
                        },
                        /*{
                            xtype: 'button',
                            text: '忘记密码',
                            style: {
                                'margin': '15px 0 0 3px',
                                'padding': '3px 10px',
                                'border-color': '#FF9800',
                                'background-image': '-webkit-linear-gradient(top, #f7ac3f, #efac4a 50%, #f79f1f 51%, #f9be67);'
                            },
                            handler: function() {

                            }
                        }*/
                        ],
                        buttons: [
                            {
                                text: '重置',
                                style: {
                                    'background': '#ccc;',
                                    'border-color': '#ccc;'
                                },
                                handler: function() {
                                    that.formPanel.getForm().reset()
                                }
                            },
                            {
                                text: '登录',
                                handler: function() {
                                    var form = this.up('form'); // get the form panel
                                    if (form.isValid()) { // make sure the form contains valid data before submitting
                                        var account = form.getForm().findField('account').getValue();
                                        that.formPanel.form.doAction('submit', {
                                            url :$.getAjaxHost('def') + 'zpinfo/login',
                                            method : 'POST',
                                            waitTitle : '连接中',
                                            waitMsg : '传送数据...',
                                            success : function() {
                                                localStorage.setItem('account',account);
                                                window.location.replace('./manage.html');
                                            },
                                            failure : function(form, action) {
                                                Ext.Msg.alert('错误提示', '非常抱歉!,登录失败');
                                                that.formPanel.getForm().reset()
                                            }
                                        });

                                    }else {
                                        Ext.Msg.alert('错误提示', '请输入账号和密码！')
                                    }
                                }
                            }
                        ]
                    });
            }
        };
        obj.init();
    });
});